<!DOCTYPE html>
<html>
<head>
<script src="/assets/jquery/jquery-3.1.1.min.js"></script>
<script src="/assets/layui-2.9.18/layui.js"></script>
<link rel="stylesheet" href="/assets/layui-2.9.18/css/layui.css">
<link rel="stylesheet" href="/assets/layui-2.9.18/css/admin.css">
<script src="/assets/september/common.js"></script>
<script src="/assets/september/htmlBuilder.js"></script>
<script src="/assets/september/search.js"></script>
<link rel="stylesheet" href="/assets/pages/form.css">
</head>
<body>
	<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin">
		<form id="form" class="layui-form">
			<div class="layui-form-item">
				<label class="layui-form-label">姓名 <em class="required">*</em>
				</label>
				<div class="layui-input-inline">
					<input type="text" name="realname" lay-verify="required|name" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">账号 <em class="required">*</em>
				</label>
				<div class="layui-input-inline">
					<input type="text" name="username" lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">密码 <em class="required">*</em>
				</label>
				<div class="layui-input-inline">
					<input type="password" name="password" lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
		    	<label class="layui-form-label">角色 <em class="required">*</em></label>
		      	<div class="layui-input-inline" style="width:350px;">
		      		<#list  roles as role>
					<input type="checkbox" roleId="${role.id}" title="${role.name!}" lay-skin="primary" class="roleId layui-input">
					</#list>
		    	</div>
	    	</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">部门 <em class="required">*</em>
				</label>
				<div class="layui-input-inline">
					<input type="text" name="deptName" lay-verify="required" value="${deptName!}" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">联系电话</label>
				<div class="layui-input-inline">
					<input type="text" name="phone" lay-verify="mobile|phone" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">电子邮箱 </label>
				<div class="layui-input-inline">
					<input type="text" name="email"  autocomplete="off" class="layui-input">
				</div>
			</div>

		</form>
		<div class="layui-form-item">
			<input type="button" class="layui-btn layui-btn-normal" style="float: right" lay-submit lay-filter="submit_button" value="确认">
		</div>
	</div>


	<script>
		layui.use(function(){
	    	var layer = layui.layer;
	    	var form = layui.form;

			/* 自定义验证规则 */
			//addVerify(form);

			form.on("submit", function(data) {
				prepareFormData(data);
				var roleId = [];
				$('.layui-form-checked').each(function(index, obj){
					roleId.push($(obj).prev().attr('roleId'));
				});
				if (roleId.length<1){
					layer.msg("至少选择一个角色");
					return;
				}
				data.field.roleIds =";"+ roleId.join(";");
				console.log(data);
				sajax({
					type : "POST",
					url : "/userPermission/systemUser/doAddSystemUser",
					data : data.field,
					dataType : 'json',
					success: function(data){
			        	layer.msg('保存成功',{shade: [0.1,'#fff'], time:1600});
			        	closeWindowAndRefreshParent();
			        }
				});
			});
	  	});
  	
	</script>
</body>
</html>
